package com.zkzx.util.data;

import java.util.Objects;

/**
 * 北京中科智兴物联科技有限公司 @版权所有
 *
 * @Author: zhaoyihe@zkraising.com
 * @Date: 2021/05/10/14:59
 * @Description:
 */
public class HideDataUtil {

    //身份证隐藏年月日，银行卡保留后四位
    public static String  getHideData(String number){

        if(Objects.isNull(number) || number.length() < 5){
            return number;
        }

        int l = number.length();
        if (l==18){
            number=number.replaceAll("(\\d{6})\\d{8}(\\d{4})", "$1****$2");
        }else if (l==15){
            number=number.replaceAll("(\\d{6})\\d{8}(\\d{1})", "$1****$2");
        }else if (l==19){
            number=number.replaceAll("(\\d{0})\\d{15}(\\d{4})", "$1****$2");
        }else if (l==17){
            number=number.replaceAll("(\\d{0})\\d{13}(\\d{4})", "$1****$2");
        }else if (l==16){
            number=number.replaceAll("(\\d{0})\\d{12}(\\d{4})", "$1****$2");
        }else {
            int length = number.length()-4;
            number=number.replaceAll("(\\d{0})\\d{"+length+"}(\\d{4})", "$1****$2");
        }

        return number;
    }
}
